﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using ShareContent;

namespace AncientEmpires_025_132
{
    public class CellMoveEffect : VisibleGameEntity
    {
        private bool _isVisiable;
        public bool IsVisiable
        {
            get { return _isVisiable; }
            set { _isVisiable = value; }
        }
        private TeamName _myTeamName;
        public TeamName MyTeamName
        {
            get { return _myTeamName; }
            set { _myTeamName = value; }
        }

        private bool _isMove;
        public bool IsMove
        {
            get { return _isMove; }
            set { _isMove = value; }
        }

        public CellMoveEffect(ContentManager content, string[] strtexture, Vector2 position, Vector2 topleft, Vector2 size)
        {
            IsMove = true;
            IsVisiable = false;
            ListSprites = new List<Sprite2D>();

            Texture2D[] texture = new Texture2D[strtexture.Length];
            for (int i = 0; i < strtexture.Length; i++)
            {
                texture[i] = content.Load<Texture2D>(strtexture[i]);
            }
            Sprite2D temp = new Sprite2D(texture, new Vector2(), new Vector2());
            temp.Size = size;
            temp.Position = position;
            temp.TopLeft = topleft;
            ISprite = 0;
            this.ListSprites.Add(temp);
            
        }
        private MouseState mouseState;
        private MouseState oldMouseState;
        public override void UpdateMouseState()
        {
            mouseState = Mouse.GetState();
            if (mouseState.X > ListSprites[ISprite].Position.X && mouseState.X < ListSprites[ISprite].Position.X + ListSprites[ISprite].Size.X
                && mouseState.Y > ListSprites[ISprite].Position.Y && mouseState.Y < ListSprites[0].Position.Y + ListSprites[ISprite].Size.Y)
            {
                if (mouseState.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed)
                {
                    //IsClick = true;
                    //ClickButton();
                    IsHover = false;
                    //IsPressed = false;
                }
                else if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    //IsClick = false;
                    //IsPressed = true;
                    IsHover = false;
                }
                else
                {
                    //IsClick = false;
                    IsHover = true;
                    //IsPressed = false;
                }
            }
            else
            {
                IsHover = false;
                //IsClick = false;
                //IsPressed = false;
            }
            oldMouseState = mouseState;
        }

        public override void Update(GameTime gametime)
        {
            UpdateMouseState();
            base.Update(gametime);
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int i = 0; i < ListSprites.Count; i++)
            {
                if (i == ISprite)
                {
                    Rectangle rect = new Rectangle();
                    if (ListSprites[i].Size.X == 0 && ListSprites[i].Size.Y == 0)
                    {
                        ListSprites[i].Size = new Vector2(ListSprites[i].Textures[ListSprites[i].ITexture].Width, ListSprites[i].Textures[ListSprites[i].ITexture].Height);
                    }
                    rect = new Rectangle((int)ListSprites[i].Position.X, (int)ListSprites[i].Position.Y, (int)ListSprites[i].Size.X, (int)ListSprites[i].Size.Y);

                    Color color = new Color();
                    if (IsMove)
                    {
                        color = Color.White;
                    }
                    else color = Color.Red;

                    spriteBatch.Draw(ListSprites[i].Textures[ListSprites[i].ITexture], rect, color * 0.4f);

                }
            }
        }
    }
}
